// pages/auth/index.js
import { request } from '../../request/index.js';
import regeneratorRuntime from '../../lib/runtime/runtime';
import {login} from '../../utils/asyncWX.js'
Page({
  // 获取用户信息
  async handleGetUserInfo(e){
    try {
      const {encryptedData,rawData,iv,signature}=e.detail;
    // 获取登陆成功后的code
    const {code} = await login();
    const loginParams={encryptedData,rawData,iv,signature,code}
    // console.log(code);

    // 发送请求 获取用户的Token值
    const {token}=await request({url:'/users/wxlogin',data:loginParams,method:"post"})
    // 把token存入缓存中，返回上一个页面
    wx.setStorageSync("token", token);
    
    wx.navigateBack({
      delta: 1
    });
    } catch (error) {
      console.log(error);
    }
  }
})